package com.eddie.factory.abstractfactory.order;

import com.eddie.factory.abstractfactory.pizza.CheesePizza;
import com.eddie.factory.abstractfactory.pizza.GreekPizza;
import com.eddie.factory.abstractfactory.pizza.PepperPizza;
import com.eddie.factory.abstractfactory.pizza.Pizza;
import com.eddie.factory.constant.PizzaConstant;
import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Eddie
 * @date 2022/4/29 11:24
 */
public class OrderPizza {
    public OrderPizza(AbsFactory factory) {
        do {
            PizzaConstant type = getType();
            if (type == null) {
                break;
            }
            Pizza pizza = factory.createPizza(type);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }

        } while (true);
    }


    @SneakyThrows
    private PizzaConstant getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("input pizza type:");
        PizzaConstant result = null;
        System.out.println("1、芝士披萨");
        System.out.println("2、希腊披萨");
        System.out.println("3、胡椒披萨");
        String s = bufferedReader.readLine();
        if ("1".equals(s)) {
            result = PizzaConstant.CHEESE_NAME;
        } else if ("2".equals(s)) {
            result = PizzaConstant.GREEK_NAME;
        } else if ("3".equals(s)) {
            result = PizzaConstant.PEPPER_NAME;
        }
        return result;
    }

}
